﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace OnlineManagement.Web.webs
{
    public partial class Main : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           if(!Page.IsPostBack){
               lbFarmName.Text = GetHoggeryName();
           }
        }

        private string GetHoggeryName() {
            int _hoggeryId=0;
            try
            {
                if (HttpContext.Current.User.Identity != null &&
                    !HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    return string.Empty;
                }
                FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
                string hoggeryIDStr = id.Ticket.UserData;

                string hoggeryName = Common.PubSessions.CacheHoggeryName;
                if (string.IsNullOrEmpty(hoggeryName))
                {
                    BLL.Dal.Hoggery bllHog = new BLL.Dal.Hoggery();
                    int.TryParse(hoggeryIDStr,out _hoggeryId);
                    
                    if (_hoggeryId != 0)
                    {
                        hoggeryName = bllHog.GetHoggeryName(_hoggeryId);
                        Common.PubSessions.CacheHoggeryName = hoggeryName;
                    }
                }
                return hoggeryName;
            }
            catch (Exception ex)
            {
                log4net.ILog log = OnlineHoggeryLog.GetLog("BaseUserControl.GetAllPigType");
                log.Error(new Com.HoggeryLog(), ex);
                return string.Empty;
            }
        }
    }
}